package org.rocky.provider.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发送消息到定时消息
 * @author Rocky
 * @date 2020/2/17 17:35
 */
@RestController
@RequestMapping("provider/ttl/")
public class SendTTLContrller {

    private RabbitTemplate rabbitTemplate;


    @Autowired
    public SendTTLContrller( RabbitTemplate rabbitTemplate){
        this.rabbitTemplate= rabbitTemplate;
    }


    /**
     * 发送延迟队列消息
     * @param info
     * @return
     */
    @RequestMapping("/sendTTL")
    public String rabbitSendTTL(String info){
        MessageProperties properties = new MessageProperties();
        properties.setExpiration("70000");
        Message message = new Message(("这条消息5秒后过期"+info).getBytes(),properties);
        rabbitTemplate.send("TTL_EXCHANGE","rocky.ttl",message);
        return "Success";
    }

}
